/**
 * 
 */
package org.metaverse.restful;

import org.metaverse.restful.SemanticException.ErrorCode;
import org.openrdf.rio.RDFFormat;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.service.StatusService;

/**
 * @author vjache
 *
 */
public class StatusServiceImpl extends StatusService {

	/**
	 * 
	 */
	public StatusServiceImpl() {
		setOverwriting(true);
	}

	/**
	 * @param enabled
	 */
	public StatusServiceImpl(boolean enabled) {
		super(enabled);
		setOverwriting(true);
	}
	
	@Override
	public Representation getRepresentation(Status status, Request request,
			Response response) {
		Throwable thr = status.getThrowable();
		if(thr==null)
			return super.getRepresentation(status, request, response);
		final SemanticException se;
		if(thr instanceof SemanticException)
		{
			se = (SemanticException)thr;
		}
		else
		{
			se = new SemanticException(RDFFormat.TRIX,ErrorCode.UnInterprettedError,thr);
		}
		
		return new StringRepresentation(
				se.toString());
	}

}
